#include<iostream>

using namespace std;

const int N = 1e5 + 10;

int n;
int q[N], hh, tt = -1;

void add(int k){
    q[++ tt] = k; 
}

void pop(){
    hh ++ ;
}

void judge(){
    if(hh <= tt) printf("NO\n");
    else printf("YES\n");
}

int main(){
    cin >> n;
    while(n -- ){
        string op;
        cin >> op;
        if(op == "push"){
            int k;
            cin >> k;
            add(k);
        }
        else if(op == "pop") pop();
        else if(op == "empty") judge();
        else cout << q[hh] << endl;
    }
    return 0;
}